import { get, post, ResultBean } from '@/utils/request';

export interface NotifyRecord {
  id: string;
  content: string;
  source: string;
  problemType: string;
  correctiveUnit: string;
  receivers: string[];
  copyDepartments: string;
  reportUnit: string;
}
export interface TaskAddDTO {
  /** 任务ID */
  taskId?: number;
  /** 督办来源 */
  source?: string;
  /** 问题类型 */
  problemType?: string;
  /** 督察要求 */
  requirements?: string;
  /** 领导批示(0-否,1-是) */
  leaderInstruction?: boolean;
  /** 批示备注 */
  leaderRemark?: string;
  /** 批示附件 */
  leaderFile?: string;
  /** 整改人员ID列表 */
  rfUsers?: any;
  rfUnits?: any;
  /** 整改开始日期(时间戳) */
  rfStartDate?: number;
  /** 整改结束日期(时间戳) */
  rfEndDate?: number;
  /** 审核人ID */
  auditor?: number;
  /** 备注 */
  remark?: string;
  /** 填报单位ID */
  reportDeptId?: number;
  /** 填报人ID */
  reportUserId?: number;
  /** 任务附件 */
  taskFile?: string;
  /** 任务状态 */
  status?: 'reject' | 'withdraw' | 'review' | 'notReceived' | 'processing' | 'processed' | 'pendingReview' | 'reviewed';
  /** 问题列表 */
  problemList?: TaskProblemDTO[];
}

export interface TaskProblemDTO {
  /** 问题ID */
  problemId?: number;
  /** 关联的任务ID */
  taskId?: number;
  /** 问题描述 */
  problemDesc?: string;
  /** 序号/索引 */
  index?: number;
  /** 问题状态 */
  status?: 'notRectified' | 'reviewed' | 'reject';
}

export type NotifyListType = NotifyRecord[];
export function queryNotifyList(params: any) {
  return post<ResultBean<NotifyRecord>>('/api/task/query', params);
}
export function withdrawTask(taskId: number) {
  return post('/api/task/withdraw', taskId);
}
export function reviewTask(data: { task: number; review: boolean; msg: string }) {
  return post('/api/task/review', data);
}
export function getTaskById(taskId) {
  return get<ResultBean<TaskAddDTO>>(`/api/task/get/${taskId}`);
}
export function getTaskAndProblemById(taskId) {
  return get<ResultBean<TaskAddDTO>>(`/api/task/getTaskAndProblemById/${taskId}`);
}
export function createTask(data) {
  return post('/api/task/create', data);
}
export function updTask(data) {
  return post('/api/task/upd', data);
}

// 接收任务
export function receiveTask(taskId: number) {
  return post('/api/task/receive', taskId);
}

export function getTaskStatus(taskId: number) {
  return get(`/api/task/getStatus/${taskId}`);
}

/**
 * 提交单个问题整改
 * @param data ProblemProcessEntity
 */
export function processProblem(data) {
  return post('/api/task/process', data);
}
//反馈任务
export function processed(data) {
  return post('/api/task/processed', data);
}

//首页统计
export interface total {
  totalCount: number;
  receiveCount: number;
  reviewCount: number;
  reviewedCount: number;
}
export function getTaskStatistics() {
  return get<total>('/api/task/statistics');
}
